<template>
  <div style="height: 100%" class="workspace">
    <el-container
      ref="listWarp"
      style="height: 100%; background-color: #fff"
      v-loading="loading"
    >
      <el-header
        class="toolbar-wap"
        style="height: 45px; line-height: 45px; margin-bottom: 2px"
      >
        <el-tabs
          v-model="activeName"
          @tab-click="handleClick"
          style="margin: 0 10px"
        >
          <el-tab-pane
            v-for="(item, index) in schoolList"
            :key="index"
            :label="item.name"
            :name="item.id"
          ></el-tab-pane>
        </el-tabs>
      </el-header>
      <div
        style="
          width: 100%;
          overflow: auto;
          overflow-x: hidden;
          display: flex;
          flex-wrap: wrap;
        "
        v-if="areaDetailsList.length > 0"
      >
        <div
          v-for="(item, index) in areaDetailsList"
          :key="index"
          style="width: 20%; height: auto; cursor: pointer"
          @click="detail(item)"
        >
          <div class="box">
            <img
              style="margin-top: -30px"
              src="../../../assets/img/lou.png"
              alt=""
            />
            <div style="margin-top: -13px; color: #3a84ef; font-size: 15px">
              <span>{{ item.buildingName }}</span>
            </div>
            <div style="display: flex">
              <div class="win" style="margin-right: 5px">
                <div>
                  <img src="../../../assets/img/fj.png" alt="" srcset="" />
                </div>
                <div style="text-align: left; margin-left: -20px">
                  <div>
                    <span class="num">{{ item.countRoom }}</span>
                  </div>
                  <div><span class="text">总房间数</span></div>
                </div>
              </div>
              <div class="win" style="margin-left: 5px">
                <div>
                  <img src="../../../assets/img/cw.png" alt="" srcset="" />
                </div>
                <div style="text-align: left; margin-left: -20px">
                  <div>
                    <span class="num">{{ item.countBeds }}</span>
                  </div>
                  <div><span class="text">总床位数</span></div>
                </div>
              </div>
            </div>
            <div
              style="
                display: flex;
                justify-content: center;
                border-bottom: 1px dashed #eaeaea;
                margin: 0 10px;
                padding-bottom: 10px;
              "
            >
              <div style="width: 33%">
                <div>
                  <span class="num" style="font-size: 20px; color: #666"
                    >{{ item.emptyRoom }}
                  </span>
                </div>
                <div>
                  <span class="text">空房间数</span>
                </div>
              </div>
              <div style="width: 33%">
                <span
                  style="
                    display: inline-block;
                    float: left;
                    width: 1px;
                    height: 18px;
                    background: #eaeaea;
                    margin-top: 15px;
                  "
                ></span>

                <div>
                  <span class="num" style="font-size: 20px; color: #666">{{
                    item.emptyRoomBeds
                  }}</span>
                </div>
                <div><span class="text">空房间床位数</span></div>
              </div>
              <div style="width: 33%">
                <span
                  style="
                    display: inline-block;
                    float: left;
                    width: 1px;
                    height: 18px;
                    background: #eaeaea;
                    margin-top: 15px;
                  "
                ></span>
                <div>
                  <span class="num" style="font-size: 20px; color: #666">{{
                    item.empetBeds
                  }}</span>
                </div>
                <div>
                  <span class="text">零星床位数</span>
                </div>
              </div>
            </div>

            <div style="" class="bot" v-if="item.result.length > 0">
              <el-carousel :interval="5000" :autoplay="false" trigger="click">
                <el-carousel-item
                  v-for="(item1, index) in item.result"
                  :key="index"
                  style="
                    display: flex;
                    align-items: center;
                    justify-content: space-around;
                  "
                >
                  <div
                    v-for="(item2, index) in item1"
                    :key="index"
                    style="width: 48%"
                  >
                    <span>{{ item2.collageName }}:</span>
                    <span style="color: #999; margin-left: 5px">{{
                      item2.count
                    }}</span>
                  </div>
                </el-carousel-item>
              </el-carousel>
            </div>
            <div style="" class="bot" v-else>
              <div
                style="
                  display: flex;
                  align-items: center;
                  height: 100%;
                  justify-content: center;
                "
              >
                <span>住宿学院:</span> <span>暂无学院</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div
        v-else
        style="
          display: flex;
          align-items: center;
          justify-content: center;
          height: 100%;
          color: #666;
        "
      >
        <span>该校区暂无楼宇</span>
      </div>
    </el-container>
  </div>
</template>

<script>
import { apiIndex } from "@/api/accommodation/index";
export default {
  components: {},
  data() {
    return {
      activeName: "",
      schoolList: [],
      areaDetailsList: [],
      loading: false,
    };
  },
  methods: {
    detail(item) {
      this.$router.push({
        path: "/accommodation/areaDetail",
        query: {
          areaId: this.activeName,
          buildingId: item.buildingId,
        },
      });
    },
    //获取校区
    funLoadAreaList() {
      apiIndex.AreaList().then((res) => {
        this.schoolList = res.data;
        this.activeName = res.data[0].id;
        this.funGetAreaDetails(res.data[0].id);
      });
    },
    //获取住宿楼
    funGetAreaDetails(id) {
      this.loading = true;
      apiIndex.GetAreaDetails(id).then((res) => {
        if (res.status == "success") {
          this.areaDetailsList = res.data;
          for (let k = 0; k < this.areaDetailsList.length; k++) {
            const element = this.areaDetailsList[k];
            var result = [];
            for (var i = 0; i < element.collage.length; i += 2) {
              result.push(element.collage.slice(i, i + 2));
            }
            element.result = result;
          }
          this.loading = false;
        }
      });
    },
    //tabs 切换
    handleClick() {
      this.funGetAreaDetails(this.activeName);
    },
  },
  created() {
    this.funLoadAreaList();
  },
  mounted() {},
};
</script>
<style lang="scss" scoped>
.workspace {
 ::v-deep .el-carousel__container {
    height: 50px;
  }
 ::v-deep .el-carousel__arrow {
    height: 16px;
    width: 16px;
  }
}
.box {
  box-shadow: 0px 0px 20px 0px rgba(228, 228, 228, 0.7);
  border-radius: 5px;
  margin: 30px 10px;
  margin-bottom: 10px;
  // border-top: 4px solid #3a84ef;
  text-align: center;
}
.win {
  width: 50%;
  height: 72px;
  background: #fafafa;
  margin: 10px 15px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}
.num {
  width: 37px;
  height: 18px;
  font-size: 22px;
  font-family: DIN;
  font-weight: bold;
  color: #333333;
}
.text {
  width: 57px;
  height: 15px;
  font-size: 13px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #666666;
}
.bot {
  font-size: 13px;
  font-family: Microsoft YaHei;
  font-weight: 300;
  color: #777777;
  height: 50px;
}
.workspace {
  ::v-deep .el-tabs__nav-wrap::after {
    width: 1px;
  }
 ::v-deep .el-dialog__headerbtn {
    // display: none;
  }
  .content {
    &:hover {
    }
  }
  .area {
    ::v-deep .el-input__inner {
      padding-left: 40px !important;
    }
  }
  .houseType {
    ::v-deep .el-input__inner {
      padding-left: 65px !important;
    }
  }
}
</style>